package generator.statements;

import generator.addons.SimpleDataGenerator;
import generator.collections.AccomodationTable;
import java.util.Random;

/**
 * Accomodation SQL record mapper.
 *
 * @author Necro
 * @author Marek Snopkowski <snpy@snpy.info>
 * @version 12.04.2008
 */
public class Accomodation extends Statement
{
    private int accomodationID;

    private Country country;
    private String name;
    private String city;
    private String address;
    private String phone;
    private String homepage;
    private String email;
    private float dayprice;

    @Override
    public int getId() {
        return accomodationID;
    }

    public String getName() {
        return name;
    }

    public Country getCountry() {
        return country;
    }

    public Accomodation(Country country, String name, String city, String address,
            String phone, String homepage, String email, float dayprice)
    {
        this.accomodationID = AccomodationTable.autoincrement();
        this.country        = country;
        this.name           = name;
        this.city           = city;
        this.address        = address;
        this.phone          = phone;
        this.homepage       = homepage;
        this.email          = email;
        this.dayprice       = dayprice;
    }

    public static Accomodation getRand(Country country){
        Random rand = new Random();

        String[][] cityNames = {
            {"Warszawa" , "Kraków" , "Gdańsk" , "Lublin" , "Sopot"},
            {"Londyn" , "Glasgow" , "Liverpool" , "Southhampton" , "Edynburg"},
            {"Stuttgart", "Hamburg", "Monachium", "Kolonia" , "Manheim"},
            {"Paryż", "Nicea", "Bordeaux", "Lion"},
            {"Egipt", "Giza", "Luxor", "Aswan"},
            {"Mediolan", "Rawenna", "Rzym", "Wenecja"}
        };

        String[] prefixesNames = {
            "Sheraton", "Radisson" , "Adagio", "Angelo", "GrandHotel"
        };

        String prefix      = prefixesNames[rand.nextInt(prefixesNames.length)];
        String newCity     = cityNames[country.getId()-1][rand.nextInt(cityNames[country.getId()-1].length)];
        String newName     = prefix.toUpperCase() + " " + newCity;
        String newPhone    = String.format("00%d0%s", country.getId(),
                SimpleDataGenerator.fillWithZeros(5,rand.nextInt(100000)));
        String newAddress  = String.format("%s Street %d", prefix, rand.nextInt(100));
        String newMail     = String.format("%s@%s.%s", prefix.toLowerCase(),
                newCity.toLowerCase(), country.getCode().toLowerCase());
        String newHomepage = String.format("www.%s.%s/%s", prefix.toLowerCase(),
                country.getCode().toLowerCase(), newCity.toString().toLowerCase());

        float newPrice = SimpleDataGenerator.getMoneyLow();

        Accomodation result = new Accomodation(country, newName, newCity, newAddress,
                newPhone, newHomepage,newMail,newPrice);

        return result;
    }

    public Object[] getFieldsValueCollection()
    {
        return new Object[]{ accomodationID, country.getId(), name, city, address,
                phone, homepage, email, dayprice };
    }

    public String getFieldsNameSet()
    {
        return "[accomodation_id], [country_id], [name], [city], [address], [phone], [homepage], [email], [day_price]";
    }
    
     @Override
    public String getTableName()
    {
        return "accomodation";
    }
}
